package com.ala4.oxcafe.repository;

import com.ala4.oxcafe.boot.page.PageDomain;
import com.ala4.oxcafe.common.utils.object.ObjectUtil;
import com.ala4.oxcafe.common.utils.text.StrUtil;
import com.ala4.oxcafe.entity.DictType;
import com.ala4.oxcafe.repository.mapper.DictTypeMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

/**
 * 字典类型
 *
 * @author PING
 * @date 2025-03-25
 */
@Repository
public class DictTypeRepository extends ServiceImpl<DictTypeMapper, DictType> implements IService<DictType> {

    public IPage<DictType> selectDictTypePage(PageDomain pageDomain, DictType dictType) {

        LambdaQueryWrapper<DictType> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.and(StrUtil.isNotEmpty(dictType.getSearchValue()), item -> {
            item.like(DictType::getTypeName, dictType.getSearchValue())
                    .or().like(DictType::getTypeCode, dictType.getSearchValue());
        });
        queryWrapper.eq(ObjectUtil.isNotNull(dictType.getStatus()), DictType::getStatus, dictType.getStatus());

        return this.page(pageDomain.toPlusPage(), queryWrapper);
    }
}
